package org.example.file;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.Set;

public class CreateTempFile {
    public static void main(String[] args) {
        try {
            String tmpDir = System.getProperty("java.io.tmpdir");
            System.err.println("temp file path:" + tmpDir);
            Path path = Files.createTempFile("hello",".file");
            System.err.println("Temp file:" + path);
            Path path1 = Files.createTempFile(null,".log");
            System.err.println("temp file:" + path1);
            Path path2 = Files.createTempFile("hello",null);
            System.err.println("temp file:" + path2);
            Path path3 = Files.createTempFile(null,null);
            System.err.println("temp file:" + path3);
            Path path4 = Files.createTempFile(Paths.get("C:\\Users\\JohnConnor\\Documents\\Downloads"),null,".log");
            System.err.println("temp file:" + path4);
            Set<PosixFilePermission> set = PosixFilePermissions.fromString("rwxrwxrwx");
            Path path5 = Files.createTempFile(Paths.get("C:\\Users\\JohnConnor\\Documents\\Downloads"),null,".log",PosixFilePermissions.asFileAttribute(set));
            System.err.println("temp file:" + path5);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
